package com.yk.faceapplication.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 自定义高度的viewpapger
 */
public class BaseViewPager extends ViewPager {
	private boolean scrollable = true;
	private float preX=0;  
	public BaseViewPager(Context context) {
		super(context);
	}

	public BaseViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/**
	 * 设置viewpager是否可以滚动
	 * 
	 * @param enable
	 */
	public void setScrollable(boolean enable) {
		scrollable = enable;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent event) {
//		if (scrollable) {
//			return super.onInterceptTouchEvent(event);
//		} else {
//			return false;
//		}
//		return false;
		
		boolean res = super.onInterceptTouchEvent(event);  
	    if(event.getAction() == MotionEvent.ACTION_DOWN) {  
	        preX = event.getX();  
	    } else {  
	        if( Math.abs(event.getX() - preX)> 4 ) {  
	            return true;  
	        } else {  
	            preX = event.getX();  
	        }  
	    }  
	    return res;  
	}
}